﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;
using Protocolo;
using Protocolo.Exception;

public partial class procesar_eventos : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        IList eventos;
        String bandera = ClientQueryString;
        string fecha;
        string dia, mes, año;
        dia = bandera.Substring(4,2);
        mes = bandera.Substring(11, 2);
        año = bandera.Substring(17, 4);
        fecha = dia + "/" + mes + "/" + año;
        Label1.Text = "EVENTOS DEL DÍA " + fecha;
        try
        {
            eventos = Control_calendario.busca_evento_dia(fecha);
        
            if (eventos.Count > 0)
            {
                // Creamos las filas y columnas.
                HtmlTableRow r = new HtmlTableRow();
                HtmlTableCell b = new HtmlTableCell();
                HtmlTableCell c = new HtmlTableCell();
                HtmlTableCell d = new HtmlTableCell();
                HtmlTableCell f = new HtmlTableCell();
                HtmlTableCell g = new HtmlTableCell();

                //Asignamos el color de fondo y el color de borde de las celdas. 
                b.BorderColor = c.BorderColor = d.BorderColor = f.BorderColor = g.BorderColor = "#FFFFFF";
                b.BgColor = c.BgColor = d.BgColor = f.BgColor = g.BgColor = "#a9a9a9";

                // Agregamos las etiquetas de la tabla.
                b.Controls.Add(new LiteralControl("<b>NOMBRE</b>"));
                d.Controls.Add(new LiteralControl("<b>HORA INICIO</b>"));
                c.Controls.Add(new LiteralControl("<b>HORA FIN</b>"));
                f.Controls.Add(new LiteralControl("<b>LUGAR</b>"));
                g.Controls.Add(new LiteralControl("<b>ANOTARSE</b>"));

                //Agregamos las columnas a la fila, y la fila a la tabla "reclamos"
                r.Cells.Add(b);
                r.Cells.Add(d);
                r.Cells.Add(c);
                r.Cells.Add(f);
                r.Cells.Add(g);
                eventos1.Rows.Add(r);

                //Recorremos la lista con los datos.
                for (int s = 0; s < eventos.Count; s++)
                {
                    Evento even = (Evento)eventos[s];
                    r = new HtmlTableRow();
                    b = new HtmlTableCell();
                    c = new HtmlTableCell();
                    d = new HtmlTableCell();
                    f = new HtmlTableCell();
                    g = new HtmlTableCell();

                    b.BorderColor = c.BorderColor = d.BorderColor = f.BorderColor = g.BgColor = "#FFFFFF";
                    b.Width = "45%";
                    c.Width = "18%";
                    d.Width = "18%";
                    f.Width = "20%";
                    if (s % 2 == 0)
                    {
                        b.BgColor = c.BgColor = d.BgColor = f.BgColor = g.BgColor = "#E0E9F5";
                    }
                    else
                    {
                        b.BgColor = c.BgColor = d.BgColor = f.BgColor = g.BgColor = "#D3D3D3";
                    }
                    string[] hora_ini = even.Hora_ini.ToString().Split(new char[] {' '});
                    string[] hora_fin = even.Hora_fin.ToString().Split(new char[] {' '});
                    b.Controls.Add(new LiteralControl(even.Nombre));
                    d.Controls.Add(new LiteralControl(hora_ini[1]));
                    c.Controls.Add(new LiteralControl(hora_fin[1]));
                    f.Controls.Add(new LiteralControl(even.Lugar));
                    g.Controls.Add(new LiteralControl("<a href='anotar_evento.aspx?ie="+ even.id_evento + "'> anotarse </a>"));
                    f.Align = "justify";
                    r.Cells.Add(b);
                    r.Cells.Add(d);
                    r.Cells.Add(c);
                    r.Cells.Add(f);
                    r.Cells.Add(g);
                    eventos1.Rows.Add(r);
                }
            }
        }
        catch (ConsultaException ce)
        {
            MessageBox.Show("Ha ocurrido un error, por favor intente mas tarde...");
            Response.Redirect("Default.aspx");
        }

    }
}
